/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.*;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;


public class ClientController implements Runnable{
    private Socket s;
    private InputStream is;
    private OutputStream os;
    private Server server;
    
    ClientController(Socket s, Server serv) throws IOException {
        this.s = s;
        this.is = s.getInputStream();
        this.os = s.getOutputStream();
        this.server = serv;
    }
    
    public void run() {
        DataInputStream in = new DataInputStream(is);
        DataOutputStream out = new DataOutputStream(os);

        boolean action = true;
        
        try {
            while(action) {
                out.writeLong(server.next());
                out.flush();
                action = in.readBoolean();
            }
        }
        catch (Exception e) {
            
        }
        finally {
            try {
                s.close();
            } catch (IOException ex) {
                System.out.println("Closing problem");
            }
        }
    }
}
